package com.lab.controller.admin;

import com.lab.common.PageResult;
import com.lab.common.Result;
import com.lab.dto.MemberDTO;
import com.lab.dto.MemberPageQueryDTO;
import com.lab.entity.Member;
import com.lab.service.MemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 成员管理
 *
 */
@RestController
@RequestMapping("/admin/member")
@Slf4j
@Api(tags="张笑成员管理接口")
public class MemberController {

    @Autowired  //在spring中找到合适的对象赋给下面的employeeService;
    private MemberService memberService;

    @PostMapping
    @ApiOperation("添加成员")
    public Result save(@RequestBody MemberDTO memberDTO){
        log.info("添加成员：{}",memberDTO);
        memberService.save(memberDTO);
        return Result.success("添加成员成功");
    }

    @GetMapping()
    @ApiOperation("员工分页查询")
    public Result<PageResult> page(MemberPageQueryDTO memberPageQueryDTO){
        log.info("查询参数为：{}", memberPageQueryDTO);
        PageResult pageResult=memberService.PageQuery(memberPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/{name}")
    @ApiOperation("根据name查询")
    public Result<Member> getByName(@PathVariable String name) {
        Member member = (Member) memberService.getByName(name);
        return Result.success(member);
    }

    @PutMapping()
    @ApiOperation("修改成员信息")
    public Result update(@RequestBody MemberDTO memberDTO){
        log.info("编辑员工：{}", memberDTO);
        memberService.update(memberDTO);
        return Result.success("修改成员成功");
    }

    @DeleteMapping
    @ApiOperation("删除分类")
    public Result deleteById(Long id){
        log.info("删除分类：{}",id);
        memberService.deleteById(id);
        return Result.success("删除分类成功");
    }

}
